﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Thunder
{
    public partial class FrmMain : Form
    {
        private Game game;
        public FrmMain()
        {
            InitializeComponent();
        }

        private void GameArea_Load(object sender, EventArgs e)
        {

        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            //初始化游戏类
            game = new Game();
            game.GameChanged += Game_GameChanged;
        }

        private void Game_GameChanged()
        {
             if (game != null)
            {
                GameArea.Invalidate();
            }
        }

        private void GameArea_Paint(object sender, PaintEventArgs e)
        {
            if (game != null)
            {
                game.Draw(e.Graphics, this.GameArea.Size);
            }
        }

        private void FrmMain_KeyDown(object sender, KeyEventArgs e)
        {
            if (game!=null)
            {
                //按键传递给Game
                game.KeyDown(e.KeyCode.ToString());
                GameArea.Invalidate();
            }
        }
    }
}
